package com.example.demo.controller;

import com.example.demo.entity.BasicUrl;
import com.example.demo.entity.HttpUri;
import com.example.demo.model.ReqBasicUrlMod;
import com.example.demo.model.ReturnMod;
import com.example.demo.repository.UriRepository;
import com.example.demo.service.UriService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;
import java.util.List;

/**
 * Created by chenbo on 2018/5/30.
 */
@RestController
@RequestMapping(value = "Http")
public class UriController {

    @Autowired
    private UriRepository uriRepository;

    @Autowired
    private UriService uriService;

    @DeleteMapping(value = "Uri")
    public ReturnMod delUri(@RequestParam(value = "id") int id){
        return uriService.delUriById ( id );
    }

    @GetMapping(value = "Uris")
    public ReturnMod getAllUri(){
        return uriService.getUris ();
    }

    @PostMapping(value = "Uri")
    public ReturnMod addUri(@RequestParam(value = "uriName") String uriName,
                            @RequestParam(value = "path") String path){
        return uriService.addUri ( uriName, path );
    }

    @PostMapping(value = "Test")
    public ReturnMod api( @RequestBody ReqBasicUrlMod mod){
        return uriService.addBasic (mod);
    }
}
